<?php
/**
 * Created by PhpStorm.
 * User: wulihao
 * Date: 2017-03-05
 * Time: 16:25
 */
function BookBack()
{
    echo "请您输入书号：";
    $book_id = trim(fgets(STDIN));
//连接数据库
    $dsn = 'mysql:dbname=school;host=192.168.137.2';
    $user = 'root';
    $password = '123456';
    $db = new PDO($dsn, $user, $password);
    try {
        $bbb = $db->exec("delete from record where bid = '$book_id'");
        if ($bbb) {
            echo "语句对了\n";
        } else if ($bbb === false) {
            echo "语句出错\n";
        } else {
            echo "内容为空，请联系管理员：110\n";
        }
    } catch (PDOException   $e) {
        echo 'Connection failed:' . $e->getMessage();
        echo "\n";
    }
//显示结果
    $bbb = ($db->query("select * from record"));
    $temp = $bbb->fetchAll(PDO::FETCH_ASSOC);
    print_r($temp);
    echo "还书成功，谢谢\n";
}